package com.thunisoft.spring3.chapter04.wizard;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractWizardFormController;

import com.thunisoft.spring3.chapter04.command.UserModel;

public class InfoFillWizardFormController extends AbstractWizardFormController {

	public InfoFillWizardFormController() {
		this.setCommandClass(UserModel.class);
		this.setCommandName("user");
	}
	
	protected Map referenceData(HttpServletRequest request, int page) throws Exception {
		Map map = new HashMap();
		if (page == 1) {
			map.put("schoolTypeList", Arrays.asList("高中","中专","大学"));
		}
		if (page == 2) {
			map.put("cityList",  Arrays.asList("济南", "北京", "上海"));
		}
		return map;
	}
	
	protected void validatePage(Object command, Errors errors, int page) {
		// 提供每一页数据的验证处理方法
	}

	protected void postProcessPage(HttpServletRequest request, Object command,
			Errors errors, int page) throws Exception {
		// 提供给每一页完成时的后处理方法
	}
	
	@Override
	protected ModelAndView processFinish(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		System.out.print(command);
		return new ModelAndView("redirect:/success");
	}
	
	protected ModelAndView processCancel(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		// 取消后的处理方法
		System.out.println(command);
		return new ModelAndView("redirect:/cancel");
	}

}
